/*
 * THE SOURCE CODES OF THE SOFTWARE ARE VALUABLE ASSETS OF FIDUS TECHNOLOGIES LTD.
 * YOU AGREE TO KEEP ALL SOURCE CODES OF THE SOFTWARE IN CONFIDENCE. YOU MAY NOT TRANSFER
 * OR ASSIGN THE SOFTWARE OR YOUR RIGHTS UNDER THIS AGREEMENT.
 * LIMITED WARRANTY
 * THE SOFTWARE AND ACCOMPANYING WRITTEN MATERIALS (INCLUDING INSTRUCTIONS FOR USE) ARE PROVIDED "AS IS"
 * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION)HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. YOU ASSUME THE ENTIRE
 * RISK AS TO THE RESULTS AND PERFORMANCE OF THE SOFTWARE.
 * FIDUS TECHNOLOGIES DOES NOT WARRANT THAT THE SOFTWARE WILL MEET ALL YOUR REQUIREMENTS, THAT OPERATIONS
 * OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ALL SOFTWARE ERRORS WILL BE CORRECTED.
 * FIDUS TECHNOLOGIES-SOFTWARE SOLUTIONS IS NOT RESPONSIBLE FOR PROBLEMS CAUSED BY CHANGES IN THE
 * OPERATING CHARACTERISTICS OF COMPUTER HARDWARE OR COMPUTER OPERATING SYSTEMS WHICH ARE MADE AFTER
 * WHICH ARE MADE AFTER THE RELEASE OF THE SOFTWARE NOR FOR PROBLEMS IN THE INTERACTION OF THE SOFTWARE
 * WITH NON-FIDUS TECHNOLOGIES APPLICATION.WILL HAVE NO RESPONSIBILITY TO REPLACE OR REFUND THE LICENSE FEES
 * FOR MEDIA DAMAGED BY ACCIDENT, ABUSE OR MISAPPLICATION. THIS SOFTWARE IS INTENDED FOR COMMERCIAL,
 * INSTITUTIONAL, AND INDUSTRIAL USERS. THE ABOVE WARRANTIES ARE EXCLUSIVE AND IN LIEU OF ALL OTHER WARRANTIES,
 * WHETHER EXPRESSED OR IMPLIED, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE AND NON-INFRINGEMENT. NO ORAL OR WRITTEN INFORMATION OR ADVICE GIVEN BY FIDUS TECHNOLOGIES,
 * ITS EMPLOYEES, DISTRIBUTORS, DEALERS OR AGENTS SHALL INCREASE THE SCOPE OF THE ABOVE WARRANTIES OR
 * CREATE ANY NEW WARRANTIES. NEITHER FIDUS TECHNOLOGIES NOR ANYONE ELSE WHO HAS BEEN INVOLVED IN THE
 * CREATION, PRODUCTION OR DELIVERY OF THE SOFTWARE SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL
 * OR INCIDENTAL DAMAGES (INCLUDING DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS LOSSES, BUSINESS
 * INTERRUPTION, LOSS OF DATA, AND THE LIKE) ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE,
 * OR ANY OTHER CLAIM BY ANY PARTY EVEN IF FIDUS TECHNOLOGIES HAS BEEN ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGES. IN THE EVENT FIDUS TECHNOLOGIES IS LIABLE FOR ANY DAMAGES, FIDUS TECHNOLOGIES' LIABILITY
 * FOR DAMAGES SHALL BE LIMITED TO THE AMOUNT PAID FOR THE SOFTWARE UNDER THE TERMS AND CONDITIONS OF THIS
 * AGREEMENT.
 * http://www.fidustechnologies.com
 * Copyright(C) 2010 FIDUS TECHNOLOGIES-Software Solutions(R)
 * All rights reserved.
 */

package com.fidus.inventory.beans.sales;

import com.fidus.inventory.beans.products.ProductDetails;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author Mahesh Kedari<mahesh.kedari@fidustechnologies.com>
 */
@Entity
@Table(name = "Sales_Order_Details")
@NamedQueries({
    @NamedQuery(name = "SalesOrderDetails.findAll", query = "SELECT s FROM SalesOrderDetails s"),
    @NamedQuery(name = "SalesOrderDetails.findByRecordID", query = "SELECT s FROM SalesOrderDetails s WHERE s.recordID = :recordID"),
    @NamedQuery(name = "SalesOrderDetails.findBySalePrice", query = "SELECT s FROM SalesOrderDetails s WHERE s.salePrice = :salePrice"),
    @NamedQuery(name = "SalesOrderDetails.findByDescription", query = "SELECT s FROM SalesOrderDetails s WHERE s.description = :description")})
public class SalesOrderDetails implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "Record_ID", nullable = false)
    private Long recordID;
    @Column(name = "Pack", length = 16)
    private String pack;
    @Column(name = "Containers")
    private Short containers;
    @Basic(optional = false)
    @Column(name = "Qty", nullable = false)
    private String qty;
    @Basic(optional = false)
    @Column(name = "Rate", nullable = false)
    private float rate;
    @Basic(optional = false)
    @Column(name = "Sale_Price", nullable = false)
    private float salePrice;
    @Basic(optional = false)
    @Column(name = "Description", nullable = false, length = 128)
    private String description;
    @JoinColumn(name = "Sales_Order_ID", referencedColumnName = "Order_ID", nullable = false)
    @ManyToOne(optional = false)
    private SalesOrder salesOrder;
    @JoinColumn(name = "Product_ID", referencedColumnName = "Product_ID", nullable = false)
    @ManyToOne(optional = false)
    private ProductDetails productDetails;

    public SalesOrderDetails() {
    }

    public SalesOrderDetails(Long recordID) {
        this.recordID = recordID;
    }

    public SalesOrderDetails(Long recordID, float salePrice, String description) {
        this.recordID = recordID;
        this.salePrice = salePrice;
        this.description = description;
    }

    public Long getRecordID() {
        return recordID;
    }

    public void setRecordID(Long recordID) {
        Long oldRecordID = this.recordID;
        this.recordID = recordID;
        changeSupport.firePropertyChange("recordID", oldRecordID, recordID);
    }

    public Short getContainers() {
        return containers;
    }

    public void setContainers(Short containers) {
        Short oldContainers = this.containers;
        this.containers = containers;
        changeSupport.firePropertyChange("containers", oldContainers, containers);
    }

    public String getPack() {
        return pack;
    }

    public void setPack(String pack) {
        String oldPack = this.pack;
        this.pack = pack;
        changeSupport.firePropertyChange("pack", oldPack, pack);
    }

    public String getQty() {
        return qty;
    }

    public void setQty(String qty) {
        String oldQty = this.qty;
        this.qty = qty;
        changeSupport.firePropertyChange("qty", oldQty, qty);
    }

    public float getRate() {
        return rate;
    }

    public void setRate(float rate) {
        float oldRate = this.rate;
        this.rate = rate;
        changeSupport.firePropertyChange("rate", oldRate, rate);
    }

    
    public float getSalePrice() {
        return salePrice;
    }

    public void setSalePrice(float salePrice) {
        float oldSalePrice = this.salePrice;
        this.salePrice = salePrice;
        changeSupport.firePropertyChange("salePrice", oldSalePrice, salePrice);
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        String oldDescription = this.description;
        this.description = description;
        changeSupport.firePropertyChange("description", oldDescription, description);
    }

    public SalesOrder getSalesOrder() {
        return salesOrder;
    }

    public void setSalesOrder(SalesOrder salesOrder) {
        SalesOrder oldSalesOrder = this.salesOrder;
        this.salesOrder = salesOrder;
        changeSupport.firePropertyChange("salesOrder", oldSalesOrder, salesOrder);
    }

    public ProductDetails getProductDetails() {
        return productDetails;
    }

    public void setProductDetails(ProductDetails productDetails) {
        ProductDetails oldProductDetails = this.productDetails;
        this.productDetails = productDetails;
        changeSupport.firePropertyChange("productDetails", oldProductDetails, productDetails);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (recordID != null ? recordID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SalesOrderDetails)) {
            return false;
        }
        SalesOrderDetails other = (SalesOrderDetails) object;
        if ((this.recordID == null && other.recordID != null) || (this.recordID != null && !this.recordID.equals(other.recordID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.fidus.inventory.beans.company.SalesOrderDetails[recordID=" + recordID + "]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

}
